// app.js
const navigateTo = wx.navigateTo, redirectTo = wx.redirectTo, switchTab = wx.switchTab;
let whitelist = [
  "/pages/login/index",
  "/pages/mine/index",
  "/pages/home/index",
  "/pages/zhenxuan/index",
  "/pages/fenlei/index",
  "/page2/yuyue/index",
  "/page5/gongsi/index",
  "/pages/gongdan/index",
]
App({
  onLaunch() {
    // wx.setStorageSync('hometofenlei', '');
  },
  onShow() {
    wx.navigateGo = (res) => {
      let url = res.url, flag = false, AccessToken = wx.getStorageSync('AccessToken');
      whitelist.forEach(item => {
        if (url == item) {
          flag = true
        }
      })
      if (flag || AccessToken) {
        navigateTo(res)
      } else {
        wx.showModal({
          title: '温馨提示',
          content: '请先登录以便获得更好的体验',
          confirmColor: '#F08302',
          showCancel: true,
          success(res) {
            if (res.confirm) {
              navigateTo({ url: "/pages/login/index" })
            }
          }
        })
      }
    };

    wx.switchTabgo = (res) => {
      let url = res.url, flag = false, AccessToken = wx.getStorageSync('AccessToken');
      whitelist.forEach(item => {
        if (url == item) {
          flag = true
        }
      })
      if (flag || AccessToken) {
        switchTab(res)
      } else {
        wx.showModal({
          title: '温馨提示',
          content: '请先登录以便获得更好的体验',
          confirmColor: '#F08302',
          showCancel: true,
          success(res) {
            if (res.confirm) {
              navigateTo({ url: "/pages/login/index" })
            }
          }
        })
      }
    }
  },
  // onLaunch() {
  //   // 展示本地存储能力
  //   const logs = wx.getStorageSync('logs') || []
  //   logs.unshift(Date.now())
  //   wx.setStorageSync('logs', logs)

  //   // 登录
  //   wx.login({
  //     success: res => {
  //       // 发送 res.code 到后台换取 openId, sessionKey, unionId
  //     }
  //   })
  // },
  // globalData: {
  //   userInfo: null
  // }  
 
})
